package yxy.game.pm2.bean.db.newDao;

import yxy.apple.db.DbManager;
import yxy.game.pm2.bean.db.po.PickedTroopsSlotPo;
import yxy.game.pm2.bean.db.po.SoulPo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jianbin
 * @date 2022/6/28 8:40
 **/
public class PickedTroopsSlotDAO {
    private static final String
            REPLACE_ONE = "replace into `pickedTroopsSlot` (`pCode`, `code`, `dataId`,`type`,`name`, `quality`, `entryId`,`value`, `isLock`,`isUse`,`reEntryId`,`reValue`, `updateTime`) " +
            "values (?,?,?,?,?,?,?,?,?,?,?,?,?)",
            SELECT_ALL = "select * from `pickedTroopsSlot` where `pCode` = ?",
            DELETE = "delete from `pickedTroopsSlot` where `pCode` = ? and `updateTime` != ?";

    public static List<PickedTroopsSlotPo> getList(String playerCode) {
        return DbManager.instance().executeQueryObjectList(SELECT_ALL, new Object[]{playerCode}, PickedTroopsSlotPo.builder);
    }

    public static boolean replace(List<PickedTroopsSlotPo> poList) {
        List<Object[]> list = new ArrayList<>();
        for (PickedTroopsSlotPo po : poList) {
            Object[] objects = new Object[]{po.getPlayerCode(),po.getCode(),po.getDataId(),po.getType(),
                    po.getName(),po.getQuality(),po.getEntryId(),po.getValue(),po.getIsLock(),po.getUse(),
                    po.getReEntryId(),po.getReValue(),po.getUpdateTime()};
            list.add(objects);
        }
        int[] ints = DbManager.instance().executeBatchCommand(REPLACE_ONE, list);
        return ints.length == poList.size();
    }

    public static void delete(String pCode, long updateTime) {
        DbManager.instance().executeCommand(DELETE, new Object[]{pCode, updateTime});
    }
}
